const Router = require('koa-router');
const { default: axios } = require('axios');
const categoryRouter = new Router({ prefix: "/category" })
categoryRouter.get('/', async (ctx, next) => {
  const res = await axios.get("http://wallpaper.apc.360.cn/index.php?c=WallPaperAndroid&a=getAllCategories")
  ctx.body = res.data;
  await next();
})
categoryRouter.post('/', async (ctx, next) => {
  console.log(ctx.request.body);
  const { count, start, cid } = ctx.request.body;
  const res = await axios.get(`http://wallpaper.apc.360.cn/index.php?c=WallPaperAndroid&a=getAppsByCategory&cid=${cid}&start=${start}&count=${count}`)
  console.log(res.data)
  ctx.body = res.data;
  await next();
})


module.exports = categoryRouter
